<?php


namespace App\Models\user;


use App\Models\base\traits\ImgTrait;
use App\Models\Model;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;

class Depart extends Model
{

    use ImgTrait , ModelTree, AdminBuilder;

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setParentColumn('pid');
        $this->setOrderColumn('created_at');
        $this->setTitleColumn('name');
    }

    protected  $fillable = [
        'created_at',
        'name',
        'type',
        'pid',
        'leader_id'
    ];

    public function getSuperiorId($depart_id)
    {
        return self::where('id',$depart_id)->value('leader_id');
    }

    public function test()
    {
        $arr = [
            [
                'type' => 1
            ],
            [
                'type' => 2
            ],
            [
                'type' => 3
            ],
            [
                'type' => 4
            ]
        ];

        foreach ($arr as $item){
            if($item['type'] == 3){
                return false;
            }
        }

        dd('test');
    }
}